using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace CodePlex.OpenSearch
{
    /// <summary>
    /// Description information for a search engine according to the opensearch 1.1 spec.
    /// </summary>
    public class SearchDefinition
    {

        private readonly OpenSearchDescription _description;
        private readonly SearchHandlerSettings _settings;




        internal SearchDefinition()
        {
            _description = new OpenSearchDescription();
            _settings = new SearchHandlerSettings(_description);
        }

        internal SearchHandlerSettings Settings 
        {
            get
            {
                return _settings;
            }
        

        }







        /// <summary>
        /// (Optional)
        /// Contains a set of words that are used as keywords to identify and categorize this search content. 
        /// Tags must be a single word
        /// Restrictions: The space-delimited value of all tags must contain 256 or fewer characters of plain text. The value must not contain HTML or other markup. 
        /// </summary>
        /// <param name="tags">Single words</param>
        public void AddTags(params string[] tags)
        {
            _description.Tags.AddRange(tags);
        }



        /// <summary>
        /// (Optional)
        /// Defines a search query that can be performed by search clients. Please see the OpenSearch Query element specification for more information.
        /// OpenSearch description documents should include at least one Query element of role="example" that is expected to return search results. Search clients may use this example query to validate that the search engine is working properly.
        /// </summary>
        /// <param name="role">
        /// Contains a string identifying how the search client should interpret the search request defined by this Query element.
        /// Restrictions: See the role values specification for allowed role values. 
        /// </param>
        /// <param name="searchTerms">
        /// Contains the value representing the "searchTerms" as an OpenSearch 1.1 parameter.
        /// Restrictions: See the "searchTerms" parameter. 
        /// </param>
        public void AddQuery(string role, string searchTerms)
        {
            _description.Queries.Add(new Query(role,searchTerms));
        }



        /// <summary>
        /// (Required)  
        /// Contains a brief human-readable title that identifies this search engine.
        /// Restrictions: The value must contain 16 or fewer characters of plain text. The value must not contain HTML or other markup. 
        /// </summary>
        public string ShortName
        {
            set
            {
                _description.ShortName = value;
            }
        }


        /// <summary>
        /// (Optional)
        /// Contains an extended human-readable title that identifies this search engine.
        /// Search clients should use the value of the ShortName element if this element is not available.
        /// Restrictions: The value must contain 48 or fewer characters of plain text. The value must not contain HTML or other markup. 
        /// </summary>
        public string LongName
        {
            set
            {
                _description.LongName = value;
            }
        }

        /// <summary>
        /// (Required)
        /// Contains a human-readable text description of the search engine.
        /// Restrictions: The value must contain 1024 or fewer characters of plain text. The value must not contain HTML or other markup. 
        /// </summary>
        public string Description
        {
            set
            {
                _description.Description = value;
            }
        }


        /// <summary>
        /// (Optional)
        /// Contains an email address at which the maintainer of the description document can be reached.
        /// Restrictions: The value must conform to the requirements of Section 3.4.1 "Addr-spec specification" in RFC 2822. 
        /// </summary>
        public string Contact
        {
            set
            {
                _description.Contact = value;
            }
        }


        /// <summary>
        /// (Optional)
        /// Contains the human-readable name or identifier of the creator or maintainer of the description document.
        /// The developer is the person or entity that created the description document, and may or may not be the owner, author, or copyright holder of the source of the content itself.
        /// Restrictions: The value must contain 64 or fewer characters of plain text. The value must not contain HTML or other markup. 
        /// </summary>
        public string Developer
        {
            set
            {
                _description.Developer = value;
            }
        }


        /// <summary>
        /// (Optional)
        /// Contains a list of all sources or entities that should be credited for the content contained in the search feed.
        /// Restrictions: The value must contain 256 or fewer characters of plain text. The value must not contain HTML or other markup. 
        /// </summary>
        public string Attribution
        {
            set
            {
                _description.Attribution = value;
            }
        }


        /// <summary>
        /// (Optional)
        /// Contains a boolean value that should be set to true if the search results may contain material intended only for adults.
        /// As there are no universally applicable guidelines as to what constitutes "adult" content, the search engine should make a good faith effort to indicate when there is a possibility that search results may contain material inappropriate for all audiences.
        /// Default: false 
        /// </summary>
        public bool AdultContent
        {
            set
            {
                _description.AdultContent = value;
            }
        }

        /// <summary>
        /// (Optional)
        /// Contains a value that indicates the degree to which the search results provided by this search engine can be queried, displayed, and redistributed.
        /// Default: Open
        /// </summary>
        public SyndicationRight SyndicationRight
        {
            set
            {
                _description.SyndicationRight = value;
            }
        }











        /// <summary>
        /// (Required)
        /// Serves as the base public url for all relative paths (scheme + authority)
        /// e.g. http://www.example.com or http://www.example.com:8080
        /// </summary>
        public string HttpBase
        {
            set
            {
                _settings.HttpBase = value;
            }
        }

        /// <summary>
        /// (Required)
        /// Relative path for OpenSearch description file
        /// e.g. /opensearch/description
        /// </summary>
        public string DescriptionPath
        {
            set
            {
                _settings.DescriptionPath = value;
            }
        }


        /// <summary>
        /// (Required)
        /// Relative path for query suggestion endpoint
        /// e.g. /opensearch/suggest
        /// </summary>
        public string SuggestPath
        {
            set
            {
                _settings.SuggestPath = value;
            }
        }


        /// <summary>
        /// (Required)
        /// Relative path for search endpoint
        /// e.g. /opensearch/search
        /// </summary>
        public string SearchPath
        {
            set
            {
                _settings.SearchPath = value;
            }
        }


      
        /// <summary>
        /// (Required)
        /// Information on the 16x16 icon file
        /// </summary>
        /// <param name="path">Relative path for 16x16 ico file</param>
        /// <param name="source">Image stream source</param>
        public void SetIco16(string path, Func<Stream> source)
        {
            _settings.ImageIco16Path = path;
            _settings.ImageIco16Source = source;
        }

        /// <summary>
        /// (Required)
        /// Information on the 64x64 png file
        /// </summary>
        /// <param name="path">Relative path for 64x64 png file</param>
        /// <param name="source">Image stream source</param>
        public void SetPng64(string path, Func<Stream> source)
        {
            _settings.ImagePng64Path = path;
            _settings.ImagePng64Source = source;
        }
     


    }
}
